<?php

class TicTacToe extends Game {

	private $field;

	public function TicTacToe(){
		parent::__construct();

	}

	public function reset(){
		$this->field = array(0,0,0,0,0,0,0,0,0);
	}

	public function sitNo(){
		return 2;
	}

	public function doAction($player, $action, $params) {
		switch($action) {
			case "set":
				$ix = $param[0];
				if($this->field[$ix]==0) {
					$this->field[$ix] = $this->turn+1;
					$this->nextPlayer();
				} 
				if($winner = $this->checkWin()) {
					echo JSON::encode(array("turn" => $this->turn, "field" => $this->field, "win" => $winner));
				} else {
					echo JSON::encode(array("turn" => $this->turn, "field" => $this->field));
				}
				break;
		}
	}

	public function json() {
		return $field;
	}
}

?>